import 'package:vista/shared/models/base_frame.dart';
import 'package:vista/shared/models/photo_params.dart';

/// 动态分类
enum PostCategory {
  dailyLife, // 日常生活
  photography, // 摄影
}

/// 时刻拍摄
/// 存储动态信息，如摄影中的时刻拍摄般记录生活瞬间
class MomentShot extends BaseFrame {
  final String id; // 动态ID
  final String authorId; // 作者ID
  final PostCategory category; // 分类
  final List<String> images; // 图片列表（3张）
  final String content; // 详情文字
  final PhotoParams? photoParams; // 摄影参数（仅摄影分类需要）
  final DateTime timestamp; // 发布时间
  final int viewCount; // 访问次数

  const MomentShot({
    required this.id,
    required this.authorId,
    required this.category,
    required this.images,
    required this.content,
    this.photoParams,
    required this.timestamp,
    this.viewCount = 0,
  });

  /// 从JSON创建时刻拍摄
  factory MomentShot.fromJson(Map<String, dynamic> json) {
    return MomentShot(
      id: json['id'] as String,
      authorId: json['authorId'] as String,
      category: PostCategory.values.firstWhere(
        (e) => e.name == json['category'] as String,
        orElse: () => PostCategory.dailyLife,
      ),
      images:
          (json['images'] as List<dynamic>).map((e) => e as String).toList(),
      content: json['content'] as String,
      photoParams:
          json['photoParams'] != null
              ? PhotoParams.fromJson(
                json['photoParams'] as Map<String, dynamic>,
              )
              : null,
      timestamp: DateTime.parse(json['timestamp'] as String),
      viewCount: json['viewCount'] as int? ?? 0,
    );
  }

  @override
  List<Object?> get props => [
    id,
    authorId,
    category,
    images,
    content,
    photoParams,
    timestamp,
    viewCount,
  ];

  @override
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'authorId': authorId,
      'category': category.name,
      'images': images,
      'content': content,
      if (photoParams != null) 'photoParams': photoParams!.toJson(),
      'timestamp': timestamp.toIso8601String(),
      'viewCount': viewCount,
    };
  }
}
